﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using CE.Mail;
using CE.Image;
using CE.Database;
using CE.AreaCountry;
using CE.Global;
using CE.PersonalAccident;
using CE.PostCode;
using CE.TravelInsurance;
using CE.User;
using CE.Security;
using CE.StreetDirectory;
using CE.Payment;

public partial class travel_insurance_hsbc_proposal_form : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session[CE.Global.General.TAId] == null)
        {
            //Response.Redirect("~/travel-insurance/travel-quote.aspx");
            Response.Redirect("~/travel-insurance/");
        }

        if (Session[CE.Global.General.TAId] != null)
        {
            if (Session[General.ProviderCompanyId] == null)
            {
                Response.Redirect("~/travel-insurance/TAresultsquotesOne.aspx");
            }
            if (Session[General.ProviderCompanyId].ToString() != "23")
            {
                Response.Redirect("~/User/ViewResultHistory.aspx");
            }
        }
        else
        {
            Response.Redirect("~/User/ViewResultHistory.aspx");
        }

        if (!Page.IsPostBack)
        {
            lblProvider.Text = "HSBC Insurance";
            //ClearSession();
            ChangeDateSettings();
            LoadSummary();

            #region Validation Effect
            txtFirstname.Attributes.Add("onblur", "ShowValidationEffect('" + txtFirstname.ClientID + "','" + rfvFirstname.ClientID + "')");
            txtSurname.Attributes.Add("onblur", "ShowValidationEffect('" + txtSurname.ClientID + "','" + rfvSurname.ClientID + "')");            
            txtEmailAddress.Attributes.Add("onblur", "ShowValidationEffectTwo('" + txtEmailAddress.ClientID + "','" + rfvEmailAddress.ClientID + "','" + revEmailAddress.ClientID + "')");
            //ddlTravellerToInsure.Attributes.Add("onblur", "ShowValidationEffect('" + ddlTravellerToInsure.ClientID + "','" + rfvravellerToInsure.ClientID + "')");

            txtNameOfInsured.Attributes.Add("onblur", "ShowValidationEffect('" + txtNameOfInsured.ClientID + "','" + rfvNameOfInsured.ClientID + "')");
            txtNRICPass.Attributes.Add("onblur", "ShowValidationEffect('" + txtNRICPass.ClientID + "','" + rfvNRICPass.ClientID + "')");

            txtInsured.Attributes.Add("onblur", "ShowValidationEffect('" + txtInsured.ClientID + "','" + rfvInsured.ClientID + "')");
            txtNRICPassInsured.Attributes.Add("onblur", "ShowValidationEffect('" + txtNRICPassInsured.ClientID + "','" + rfvNRICPassInsured.ClientID + "')");
            txtSpouse.Attributes.Add("onblur", "ShowValidationEffect('" + txtSpouse.ClientID + "','" + rfvSpouse.ClientID + "')");
            txtNRICPassSpouse.Attributes.Add("onblur", "ShowValidationEffect('" + txtNRICPassSpouse.ClientID + "','" + rfvNRICPassSpouse.ClientID + "')");

            txtInsuredFamily.Attributes.Add("onblur", "ShowValidationEffect('" + txtInsuredFamily.ClientID + "','" + rfvInsuredFamily.ClientID + "')");
            txtNRICPassInsuredFamily.Attributes.Add("onblur", "ShowValidationEffect('" + txtNRICPassInsuredFamily.ClientID + "','" + rfvNRICPassInsuredFamily.ClientID + "')");
            txtSpouseFamily.Attributes.Add("onblur", "ShowValidationEffect('" + txtSpouseFamily.ClientID + "','" + rfvSpouseFamily.ClientID + "')");
            txtNRICPassSpouseFamily.Attributes.Add("onblur", "ShowValidationEffect('" + txtNRICPassSpouseFamily.ClientID + "','" + rfvNRICPassSpouseFamily.ClientID + "')");
            txtNoOfChild.Attributes.Add("onblur", "ShowValidationEffect('" + txtNoOfChild.ClientID + "','" + rfvNoOfChild.ClientID + "')");

            txtNameoftheCard.Attributes.Add("onblur", "ShowValidationEffect('" + txtNameoftheCard.ClientID + "','" + rfvNameoftheCard.ClientID + "')");
            txtIssuingBank.Attributes.Add("onblur", "ShowValidationEffect('" + txtIssuingBank.ClientID + "','" + rfvIssuingBank.ClientID + "')");
            txtCardNo1.Attributes.Add("onblur", "ShowValidationEffectTwo('" + txtCardNo1.ClientID + "','" + rfvCardNo1.ClientID + "','" + revCardNo1.ClientID + "')");
            txtCardNo2.Attributes.Add("onblur", "ShowValidationEffectTwo('" + txtCardNo2.ClientID + "','" + rfvCardNo2.ClientID + "','" + revCardNo2.ClientID + "')");
            txtCardNo3.Attributes.Add("onblur", "ShowValidationEffectTwo('" + txtCardNo3.ClientID + "','" + rfvCardNo3.ClientID + "','" + revCardNo3.ClientID + "')");
            txtCardNo4.Attributes.Add("onblur", "ShowValidationEffectTwo('" + txtCardNo4.ClientID + "','" + rfvCardNo4.ClientID + "','" + revCardNo4.ClientID + "')");
            ddlCardExpiryMonth.Attributes.Add("onblur", "ShowValidationEffect('" + ddlCardExpiryMonth.ClientID + "','" + rfvCardExpiryMonth.ClientID + "')");
            ddlCardExpiryYear.Attributes.Add("onblur", "ShowValidationEffect('" + ddlCardExpiryYear.ClientID + "','" + rfvCardExpiryYear.ClientID + "')");

            txtAdultName1.Attributes.Add("onblur", "ShowValidationEffectTwo('" + txtAdultName1.ClientID + "','" + rfvAdultName1.ClientID + "','" + revAdultName1.ClientID + "')");
            txtAdultName2.Attributes.Add("onblur", "ShowValidationEffectTwo('" + txtAdultName2.ClientID + "','" + rfvAdultName2.ClientID + "','" + revAdultName2.ClientID + "')");
            txtChildName1.Attributes.Add("onblur", "ShowValidationEffectTwo('" + txtChildName1.ClientID + "','" + rfvChildName1.ClientID + "','" + revChildName1.ClientID + "')");
            txtChildName2.Attributes.Add("onblur", "ShowValidationEffectTwo('" + txtChildName2.ClientID + "','" + rfvChildName2.ClientID + "','" + revChildName2.ClientID + "')");
            txtChildName3.Attributes.Add("onblur", "ShowValidationEffectTwo('" + txtChildName3.ClientID + "','" + rfvChildName3.ClientID + "','" + revChildName3.ClientID + "')");
            txtChildName4.Attributes.Add("onblur", "ShowValidationEffectTwo('" + txtChildName4.ClientID + "','" + rfvChildName4.ClientID + "','" + revChildName4.ClientID + "')");
            txtChildName5.Attributes.Add("onblur", "ShowValidationEffectTwo('" + txtChildName5.ClientID + "','" + rfvChildName5.ClientID + "','" + revChildName5.ClientID + "')");

            rdoVisa.Attributes.Add("onblur", "CheckCardTypeValidationCss();");
            rdoMasterCard.Attributes.Add("onblur", "CheckCardTypeValidationCss();");
            #endregion

            txtUnit2.Attributes.Add("onkeyup", "ShowHideDiv('divInsured',true);");
            txtNRICPass.Attributes.Add("onkeyup", "ShowHideDiv('divPaymentMode',true);");
            txtNRICPassSpouse.Attributes.Add("onkeyup", "ShowHideDiv('divPaymentMode',true);");
            txtNRICPassSpouseFamily.Attributes.Add("onkeyup", "ShowHideDiv('divPaymentMode',true);");

            int _year;
            int startyear = CE.Global.General.GetUTCDateTime().Year;
            int endyear = CE.Global.General.GetUTCDateTime().Year + 10;
            for (_year = endyear; _year >= startyear; _year--)
            {
                ddlCardExpiryYear.Items.Insert(0, new ListItem(_year.ToString("0000"), _year.ToString("00")));
            }
            ddlCardExpiryYear.Items.Insert(0, new ListItem("yyyy", "-1"));

            Session[General.ViewedDetailsId] = LogUserViewedHistory().ToString();
            

            if (Session[General.UserId] != null)
            {
                ShowUserDetails();
            }
            else if (Session[General.TAPersonnelId] != null
                && Session[General.TAUserName] != null
                && Session[General.TAPhoneNo] != null
                && Session[General.TAEmail] != null)
            {
                txtFirstname.Text = Session[General.TAUserName].ToString();
                txtMobileNo.PhoneNo = Session[General.TAPhoneNo].ToString();
                txtEmailAddress.Text = Session[General.TAEmail].ToString();
            }
        }
        if (rdoVisa.Checked || rdoMasterCard.Checked) txtCardType.Text = "1";


    }

    protected void LoadSummary()
    {
        Int64 TAId = 0;

        TAApplicantSearchDB _taapplicantsearchdb = new TAApplicantSearchDB();
        TAApplicantSearch _taapplicantsearch = new TAApplicantSearch();

        if (Session[General.TAId] != null)
            TAId = Convert.ToInt64(Session[General.TAId]);

        _taapplicantsearch = _taapplicantsearchdb.GetTAApplicantSearchItem(TAId);

        if (_taapplicantsearch != null)
        {
            string convertno = General.GetRefNumber(Convert.ToInt64(Session[General.TAId].ToString()));            
            lblQref.Text = "TIH" + convertno;            
            lblCoverageType.Text = GetCoverage(_taapplicantsearch.TripType.ToString());
            lblTrip.Text = _taapplicantsearch.TripType.ToString();
            lblCover.Text = _taapplicantsearch.CoverageLevel.ToString();            
            lblCoverage.Text = _taapplicantsearch.CoverageLevel.ToString();
            lblTotalPremium.Text = "$ " + _taapplicantsearch.TotalPremium.ToString();
            lblNoOfTravellers.Text = _taapplicantsearch.NoOfTravellers.ToString();
            inNoOfTravellers.Value = _taapplicantsearch.NoOfTravellers.ToString();
            //lblInsCoverage.Text = GetPlanName(_taapplicantsearch.PlanType.ToString(), _taapplicantsearch.CoverageLevel.ToString());
            lblDuration.Text = _taapplicantsearch.Duration.ToString();
            lblAdultAge.Text = _taapplicantsearch.AdultAge.ToString();
            lblChildAge.Text = _taapplicantsearch.ChildAge.ToString();

            txtNoOfTravellers.Text = _taapplicantsearch.NoOfTravellers.ToString();
            txtNoOfChild.Text = _taapplicantsearch.NoofChilds.ToString();
            txtNoOfAdult.Text = _taapplicantsearch.NoofAdults.ToString();
            Int32 _AdultCount = Convert.ToInt32(txtNoOfAdult.Text.Trim());

            if (_AdultCount == 1 && _taapplicantsearch.PlanType.ToString() == "FML")
                lblPolicyType.Text = GetPolicy(_taapplicantsearch.PlanType.ToString()) + " (Individual + Child)";
            else
                lblPolicyType.Text = GetPolicy(_taapplicantsearch.PlanType.ToString());

            if (_AdultCount == 2 && _taapplicantsearch.PlanType.ToString() == "FML")
                divFamilySpouse.Visible = true;
            else
                divFamilySpouse.Visible = false;

            if (_taapplicantsearch.TripType == "A")
            {
                lblPeriodOfCoverage.Text = String.Format("{0:dd/MM/yyyy}", _taapplicantsearch.StartDate);
                lblStart.Text = _taapplicantsearch.StartDate.ToString();
                lblEnd.Text = _taapplicantsearch.StartDate.ToString();
            }
            else
            {
                lblPeriodOfCoverage.Text = String.Format("{0:dd/MM/yyyy} To {1:dd/MM/yyyy}", _taapplicantsearch.StartDate, _taapplicantsearch.EndDate);
                lblStart.Text = _taapplicantsearch.StartDate.ToString();
                lblEnd.Text = _taapplicantsearch.EndDate.ToString();

            }

            if (_taapplicantsearch.AreaID != 0)
                lblDestination.Text = GetAreaName(_taapplicantsearch.AreaID);
            else
                lblDestination.Text = GetCountryName(_taapplicantsearch.CountryID);


            //if (lblPolicyType.Text == "Family")
            //{
            //    txtNoOfChild.Text = _taapplicantsearch.NoofChilds.ToString();
            //}

            //Insurer
            usrDOB.Day = _taapplicantsearch.DOBAdult1.Day;
            usrDOB.Month = _taapplicantsearch.DOBAdult1.Month;
            usrDOB.Year = _taapplicantsearch.DOBAdult1.Year;

            usrDOBinsured.Day = _taapplicantsearch.DOBAdult1.Day;
            usrDOBinsured.Month = _taapplicantsearch.DOBAdult1.Month;
            usrDOBinsured.Year = _taapplicantsearch.DOBAdult1.Year;

            usrDOBInsuredFamily.Day = _taapplicantsearch.DOBAdult1.Day;
            usrDOBInsuredFamily.Month = _taapplicantsearch.DOBAdult1.Month;
            usrDOBInsuredFamily.Year = _taapplicantsearch.DOBAdult1.Year;

            //Spouse
            usrDOBSpouse.Day = _taapplicantsearch.DOBAdult2.Day;
            usrDOBSpouse.Month = _taapplicantsearch.DOBAdult2.Month;
            usrDOBSpouse.Year = _taapplicantsearch.DOBAdult2.Year;

            usrDOBSpouseFamily.Day = _taapplicantsearch.DOBAdult2.Day;
            usrDOBSpouseFamily.Month = _taapplicantsearch.DOBAdult2.Month;
            usrDOBSpouseFamily.Year = _taapplicantsearch.DOBAdult2.Year;
            

            if(_AdultCount > 2)
            {
                ddlAdultDOB1.Day = _taapplicantsearch.DOBAdult3.Day;
                ddlAdultDOB1.Month = _taapplicantsearch.DOBAdult3.Month;
                ddlAdultDOB1.Year = _taapplicantsearch.DOBAdult3.Year;

                ddlAdultDOB2.Day = _taapplicantsearch.DOBAdult4.Day;
                ddlAdultDOB2.Month = _taapplicantsearch.DOBAdult4.Month;
                ddlAdultDOB2.Year = _taapplicantsearch.DOBAdult4.Year;

                pnlAdultsParticulars.Visible = true;
                if(_AdultCount == 3)
                {
                    pnlAdult1.Visible = true;
                    pnlAdult2.Visible = false;

                    ValidateAdult1(true);
                    ValidateAdult2(false);
                }
                else if(_AdultCount == 4)
                {
                    pnlAdult1.Visible = true;
                    pnlAdult2.Visible = true;

                    ValidateAdult1(true);
                    ValidateAdult2(true);
                }
            }
            else
            {
                pnlAdultsParticulars.Visible = false;
                ValidateAdult1(false);
                ValidateAdult2(false);
            }
            Int32 _ChildCount = Convert.ToInt32(txtNoOfChild.Text.Trim());
            if (_ChildCount > 0)
            {
                ddlChildDOB1.Day = _taapplicantsearch.DOBChild1.Day;
                ddlChildDOB1.Month = _taapplicantsearch.DOBChild1.Month;
                ddlChildDOB1.Year = _taapplicantsearch.DOBChild1.Year;

                ddlChildDOB2.Day = _taapplicantsearch.DOBChild2.Day;
                ddlChildDOB2.Month = _taapplicantsearch.DOBChild2.Month;
                ddlChildDOB2.Year = _taapplicantsearch.DOBChild2.Year;

                ddlChildDOB3.Day = _taapplicantsearch.DOBChild3.Day;
                ddlChildDOB3.Month = _taapplicantsearch.DOBChild3.Month;
                ddlChildDOB3.Year = _taapplicantsearch.DOBChild3.Year;

                ddlChildDOB4.Day = _taapplicantsearch.DOBChild4.Day;
                ddlChildDOB4.Month = _taapplicantsearch.DOBChild4.Month;
                ddlChildDOB4.Year = _taapplicantsearch.DOBChild4.Year;

                ddlChildDOB5.Day = _taapplicantsearch.DOBChild5.Day;
                ddlChildDOB5.Month = _taapplicantsearch.DOBChild5.Month;
                ddlChildDOB5.Year = _taapplicantsearch.DOBChild5.Year;
                
                ddlChildDOB6.Day = _taapplicantsearch.DOBChild6.Day;
                ddlChildDOB6.Month = _taapplicantsearch.DOBChild6.Month;
                ddlChildDOB6.Year = _taapplicantsearch.DOBChild6.Year;


                pnlChildsParticulars.Visible = true;
                if (_ChildCount == 1)
                {
                    pnlChild1.Visible = true;
                    pnlChild2.Visible = false;
                    pnlChild3.Visible = false;
                    pnlChild4.Visible = false;
                    pnlChild5.Visible = false;
                    pnlChild6.Visible = false;

                    ValidateChild1(true);
                    ValidateChild2(false);
                    ValidateChild3(false);
                    ValidateChild4(false);
                    ValidateChild5(false);
                    ValidateChild6(false);
                }
                else if (_ChildCount == 2)
                {
                    pnlChild1.Visible = true;
                    pnlChild2.Visible = true;
                    pnlChild3.Visible = false;
                    pnlChild4.Visible = false;
                    pnlChild5.Visible = false;
                    pnlChild6.Visible = false;

                    ValidateChild1(true);
                    ValidateChild2(true);
                    ValidateChild3(false);
                    ValidateChild4(false);
                    ValidateChild5(false);
                    ValidateChild6(false);
                }
                else if (_ChildCount == 3)
                {
                    pnlChild1.Visible = true;
                    pnlChild2.Visible = true;
                    pnlChild3.Visible = true;
                    pnlChild4.Visible = false;
                    pnlChild5.Visible = false;
                    pnlChild6.Visible = false;

                    ValidateChild1(true);
                    ValidateChild2(true);
                    ValidateChild3(true);
                    ValidateChild4(false);
                    ValidateChild5(false);
                    ValidateChild6(false);
                }
                else if (_ChildCount == 4)
                {
                    pnlChild1.Visible = true;
                    pnlChild2.Visible = true;
                    pnlChild3.Visible = true;
                    pnlChild4.Visible = true;
                    pnlChild5.Visible = false;
                    pnlChild6.Visible = false;

                    ValidateChild1(true);
                    ValidateChild2(true);
                    ValidateChild3(true);
                    ValidateChild4(true);
                    ValidateChild5(false);
                    ValidateChild6(false);
                }
                else if (_ChildCount == 5)
                {
                    pnlChild1.Visible = true;
                    pnlChild2.Visible = true;
                    pnlChild3.Visible = true;
                    pnlChild4.Visible = true;
                    pnlChild5.Visible = true;
                    pnlChild6.Visible = false;

                    ValidateChild1(true);
                    ValidateChild2(true);
                    ValidateChild3(true);
                    ValidateChild4(true);
                    ValidateChild5(true);
                    ValidateChild6(false);
                }
                else if (_ChildCount == 6)
                {
                    pnlChild1.Visible = true;
                    pnlChild2.Visible = true;
                    pnlChild3.Visible = true;
                    pnlChild4.Visible = true;
                    pnlChild5.Visible = true;
                    pnlChild6.Visible = true;

                    ValidateChild1(true);
                    ValidateChild2(true);
                    ValidateChild3(true);
                    ValidateChild4(true);
                    ValidateChild5(true);
                    ValidateChild6(true);
                }
            }
            else
            {
                pnlChildsParticulars.Visible = false;
                ValidateChild1(false);
                ValidateChild2(false);
                ValidateChild3(false);
                ValidateChild4(false);
                ValidateChild5(false);
                ValidateChild6(false);
            }

        }
    }

    protected string GetPlanName(string plantype, string coveragelevel)
    {
        string planname = "";
        TAQuoteResult _taresult = new TAQuoteResult();
        TAQuoteResultDB _tadb = new TAQuoteResultDB();

        _taresult = _tadb.GetTASelectSingleItemSelected(Convert.ToInt64(Session[CE.Global.General.ProviderCompanyId].ToString()), GetPolicy(plantype), coveragelevel);

        if (_taresult != null)
        {
            planname = _taresult.PlanName;
        }

        return planname;
    }

    protected string GetPolicy(string covertype)
    {
        string policy = "family";
        divIndividual.Visible = false;
        divWithspouse.Visible = false;
        divFamily.Visible = false;

        ddlGenderIndividual.IsEnableValidation(false);
        ddlGenderSpouse.IsEnableValidation(false);
        ddlGenderWithSpouse.IsEnableValidation(false);
        ddlGenderFamily.IsEnableValidation(false);
        ddlGenderSpouseFamily.IsEnableValidation(false);

        if (covertype == "IND")
        {
            policy = "Individual";
            divIndividual.Visible = true;
            ddlGenderIndividual.IsEnableValidation(true);
        }
        else if (covertype == "INS")
        {
            policy = "Individual + Spouse";
            divWithspouse.Visible = true;
            ddlGenderWithSpouse.IsEnableValidation(true);
            ddlGenderSpouse.IsEnableValidation(true);
        }
        else if (covertype == "INC")
        {
            policy = "Individual + Child";
            divIndividual.Visible = true;
            ddlGenderIndividual.IsEnableValidation(true);
        }
        else if (covertype == "FML")
        {
            policy = "Family";
            divFamily.Visible = true;
            ddlGenderFamily.IsEnableValidation(true);
            ddlGenderSpouseFamily.IsEnableValidation(true);
        }

        return policy;
    }

    protected string GetCoverage(string coverage)
    {
        string cover = "Single Trip";

        if (coverage == "A")
            cover = "Annual Multi-trip";

        return cover;
    }

    protected string GetCoverageLevel(string coverage)
    {
        string coveragelevel = "Standard";

        if (coverage == "STD")
            coveragelevel = "Standard";
        else if (coverage == "MED")
            coveragelevel = "Medium";
        else if (coverage == "HGH")
            coveragelevel = "High";

        return coveragelevel;
    }

    protected string GetAreaName(Int64 areaid)
    {
        string Area = "";

        AreaInfo _areainfo = new AreaInfo();
        AreaInfoDB _areainfodb = new AreaInfoDB();

        _areainfo = _areainfodb.GetAreaInfo(areaid);

        Area = _areainfo.Description;

        return Area;

    }

    protected string GetCountryName(Int64 countryid)
    {
        string Country = "";

        CountryInfo _countryinfo = new CountryInfo();
        CountryInfoDB _countryinfodb = new CountryInfoDB();

        _countryinfo = _countryinfodb.GetCountryInfo(countryid);

        Country = _countryinfo.Description;

        return Country;

    }

    protected void ibtSubmit_Click(object sender, ImageClickEventArgs e)
    {
        CheckValidation();
        ChangeValidationEffectServerSide("travel_insurance");

        if (IsValid)
        {
            Int64 _tamoreresult = 0;
            TAMoreDetailHsbc _tamoredetailhsbc = new TAMoreDetailHsbc();
            TAMoreDetailHsbcDB _tamoredetailhsbcdb = new TAMoreDetailHsbcDB();


            _tamoredetailhsbc.cetaMoreDetailId = 0;
            _tamoredetailhsbc.cetaInsId = Convert.ToInt64(Session[General.TAResultId].ToString());
            _tamoredetailhsbc.cetaId = Convert.ToInt64(Session[General.TAId].ToString()); //TAAppSeaID 
            _tamoredetailhsbc.ProviderCompanyId = Convert.ToInt64(Session[General.ProviderCompanyId].ToString());
            _tamoredetailhsbc.Name = txtSurname.Text.ToUpper() + " " + txtFirstname.Text.ToUpper();
            _tamoredetailhsbc.PostalCode = txtPostCode.Text;
            _tamoredetailhsbc.UnitNo = txtUnit1.Text.Trim();
            _tamoredetailhsbc.HomeNo = txtUnit2.Text.Trim();
            _tamoredetailhsbc.Address = txtAddress.Text.Trim();
            _tamoredetailhsbc.NRICNo = "";
            _tamoredetailhsbc.Nationality = ddlNationality.GetNationality();
            _tamoredetailhsbc.MobileNo = txtMobileNo.GetPhoneNo();
            _tamoredetailhsbc.HomePhoneNo = txtResidentialPhoneNo.GetPhoneNo();
            _tamoredetailhsbc.OfficePhoneNo = txtOfficeNo.GetPhoneNo();
            _tamoredetailhsbc.FaxNo = "";
            _tamoredetailhsbc.EmpName = "";
            //_tamoredetailhsbc.PlanName = lblInsCoverage.Text;

            string policytype = "";
            if (lblPolicyType.Text == "Family (Individual + Child)")
                policytype = "Family";
            else
                policytype = lblPolicyType.Text;

            _tamoredetailhsbc.PlanType = policytype;
            _tamoredetailhsbc.TripType = lblTrip.Text;
            _tamoredetailhsbc.CoverageLevel = lblCover.Text;
            _tamoredetailhsbc.Country = lblDestination.Text;
            _tamoredetailhsbc.Area = lblDestination.Text;
            _tamoredetailhsbc.Duration = lblDuration.Text;
            _tamoredetailhsbc.StartDate = DateTime.Parse(lblStart.Text);
            _tamoredetailhsbc.EndDate = DateTime.Parse(lblEnd.Text);
            _tamoredetailhsbc.AdultAge = Convert.ToInt32(lblAdultAge.Text);
            _tamoredetailhsbc.ChildAge = Convert.ToInt32(lblChildAge.Text);
            _tamoredetailhsbc.NoOfTraveller = Convert.ToInt32(lblNoOfTravellers.Text);
            _tamoredetailhsbc.TotalPremium = float.Parse(lblTotalPremium.Text.Remove(0, 2));
            _tamoredetailhsbc.PamentType = "CreditCard";
            _tamoredetailhsbc.Info1 = txtEmailAddress.Text;
            _tamoredetailhsbc.Info2 = Session[General.TAId].ToString(); //AppSeaID
            _tamoredetailhsbc.Info3 = ddlGender.GetGender(); //For Gender - Sakthi on 23/Nov/2010
        
            if (Session[General.UserId] != null)
                _tamoredetailhsbc.RefCEUserId = Convert.ToInt64(Session[General.UserId].ToString());
            else
                _tamoredetailhsbc.RefCEUserId = Convert.ToInt64(Session[CE.Global.General.TAPersonnelId].ToString());


            _tamoredetailhsbc.ViewedDetailId = Convert.ToInt64(Session[General.ViewedDetailsId].ToString());
            _tamoredetailhsbc.Status = true;

            _tamoreresult = _tamoredetailhsbcdb.Insert(_tamoredetailhsbc);

            Int64 TATraId = 0;
            if (_tamoreresult > 0)
            {
                Int64 _paymentresult = 0;
                Payment _payment = new Payment();
                PaymentDB _paymentdb = new PaymentDB();

                _payment.CXPaymentId = 0;
                _payment.RefId = Convert.ToInt64(Session[General.TAId].ToString()); //_tamoreresult; 
                _payment.ProviderCompanyId = Convert.ToInt64(Session[General.ProviderCompanyId].ToString());
                _payment.InsuranceType = "TI";
                _payment.NameoftheCard = txtNameoftheCard.Text.ToUpper();
                _payment.IssuingBankName = txtIssuingBank.Text.Trim();
                _payment.CreditCardNo = txtCardNo1.Text.Trim() + "" + txtCardNo2.Text.Trim() + "" + txtCardNo3.Text.Trim() + "" + txtCardNo4.Text.Trim();
                _payment.CardExpiryMonth = ddlCardExpiryMonth.Text;
                _payment.CardExpiryYear = ddlCardExpiryYear.Text;
                if (rdoVisa.Checked == true)
                {
                    _payment.CardType = "Visa";
                }
                else
                {
                    _payment.CardType = "MasterCard";
                }
                _payment.Status = true;
                if (Session[CE.Global.General.UserId] != null)
                {
                    _payment.RefCEUserId = Convert.ToInt64(Session[CE.Global.General.UserId].ToString());
                }
                else
                {
                    _payment.RefCEUserId = Convert.ToInt64(Session[CE.Global.General.TAPersonnelId].ToString());
                }

                _paymentresult = _paymentdb.Insert(_payment);

                if (_paymentresult > 0)
                {
                    //Save Travellers to Insure

                    int NoOfTravellers = 0; // Convert.ToInt32(lblNoOfTravellers.Text.ToString());

                    string salutation = "";
                    string idtype = "";
                    string gender = "";
                    string fullname = "";
                    string idnum = "";
                    DateTime birthday = CE.Global.General.GetUTCDateTime();
                    string nationality = "";
                    string relationship = "";

                    //if (divIndividual.Visible == true)
                    //{
                    //    NoOfTravellers = 1;
                    //}
                    //else if (divWithspouse.Visible == true || divFamily.Visible == true)
                    //{
                    //    NoOfTravellers = 2;
                    //}
                    NoOfTravellers = Convert.ToInt32(txtNoOfTravellers.Text.Trim());

                    TATravellersToInsure _tatravellerstoinsure = new TATravellersToInsure();
                    TATravellersToInsureDB _tatravellerstoinsuredb = new TATravellersToInsureDB();



                    for (int i = 1; i <= NoOfTravellers; i++)
                    {
                        if (divIndividual.Visible == true)
                        {
                            if (i == 1)
                            {
                                fullname = txtNameOfInsured.Text.ToUpper();
                                idnum = txtNRICPass.Text;
                                birthday = usrDOB.GetDate();
                                nationality = ddlNationality.GetNationality();
                                relationship = "Proposer";
                                gender = ddlGender.GetGender();
                            }
                            if (i == 2)
                            {
                                fullname = txtChildName1.Text.ToUpper();
                                idnum = ddlChildIdNumber1.GetIdNumber();
                                birthday = ddlChildDOB1.GetDate();
                                relationship = "Child";
                                gender = ddlGenderChild1.GetGender();
                            }
                            if (i == 3)
                            {
                                fullname = txtChildName2.Text.ToUpper();
                                idnum = ddlChildIdNumber2.GetIdNumber();
                                birthday = ddlChildDOB2.GetDate();
                                relationship = "Child";
                                gender = ddlGenderChild2.GetGender();
                            }
                            if (i == 4)
                            {
                                fullname = txtChildName3.Text.ToUpper();
                                idnum = ddlChildIdNumber3.GetIdNumber();
                                birthday = ddlChildDOB3.GetDate();
                                relationship = "Child";
                                gender = ddlGenderChild3.GetGender();
                            }
                            if (i == 5)
                            {
                                fullname = txtChildName4.Text.ToUpper();
                                idnum = ddlChildIdNumber4.GetIdNumber();
                                birthday = ddlChildDOB4.GetDate();
                                relationship = "Child";
                                gender = ddlGenderChild4.GetGender();
                            }
                            if (i == 6)
                            {
                                fullname = txtChildName5.Text.ToUpper();
                                idnum = ddlChildIdNumber5.GetIdNumber();
                                birthday = ddlChildDOB5.GetDate();
                                relationship = "Child";
                                gender = ddlGenderChild5.GetGender();
                            }
                            if (i == 7)
                            {
                                fullname = txtChildName6.Text.ToUpper();
                                idnum = ddlChildIdNumber6.GetIdNumber();
                                birthday = ddlChildDOB6.GetDate();
                                relationship = "Child";
                                gender = ddlGenderChild6.GetGender();
                            }
                        } 
                        else if (divWithspouse.Visible == true)
                        {
                            if (i == 1)
                            {
                                fullname = txtInsured.Text.ToUpper();
                                idnum = txtNRICPassInsured.Text;
                                birthday = usrDOBinsured.GetDate();
                                nationality = ddlNationality.GetNationality();
                                relationship = "Proposer";
                                gender = ddlGenderWithSpouse.GetGender();
                            }
                            else
                            {
                                fullname = txtSpouse.Text.ToUpper();
                                idnum = txtNRICPassSpouse.Text;
                                birthday = usrDOBSpouse.GetDate();
                                nationality = ddlNationality.GetNationality();
                                relationship = "Spouse";
                                gender = ddlGenderSpouse.GetGender();
                            }

                        }
                        else if (divFamily.Visible == true)
                        {
                            if (i == 1)
                            {
                                fullname = txtInsuredFamily.Text.ToUpper();
                                idnum = txtNRICPassInsuredFamily.Text;
                                birthday = usrDOBInsuredFamily.GetDate();
                                nationality = ddlNationality.GetNationality();
                                relationship = "Proposer";
                                gender = ddlGenderFamily.GetGender();
                            }
                            if (Convert.ToInt32(txtNoOfAdult.Text.Trim()) == 2)
                            {
                                if (i == 2)
                                {
                                    fullname = txtSpouseFamily.Text.ToUpper();
                                    idnum = txtNRICPassSpouseFamily.Text;
                                    birthday = usrDOBSpouseFamily.GetDate();
                                    nationality = ddlNationality.GetNationality();
                                    relationship = "Spouse";
                                    gender = ddlGenderSpouseFamily.GetGender();
                                }
                                if (i == 3)
                                {
                                    fullname = txtChildName1.Text.ToUpper();
                                    idnum = ddlChildIdNumber1.GetIdNumber();
                                    birthday = ddlChildDOB1.GetDate();
                                    relationship = "Child";
                                    gender = ddlGenderChild1.GetGender();
                                }
                                if (i == 4)
                                {
                                    fullname = txtChildName2.Text.ToUpper();
                                    idnum = ddlChildIdNumber2.GetIdNumber();
                                    birthday = ddlChildDOB2.GetDate();
                                    relationship = "Child";
                                    gender = ddlGenderChild2.GetGender();
                                }
                                if (i == 5)
                                {
                                    fullname = txtChildName3.Text.ToUpper();
                                    idnum = ddlChildIdNumber3.GetIdNumber();
                                    birthday = ddlChildDOB3.GetDate();
                                    relationship = "Child";
                                    gender = ddlGenderChild3.GetGender();
                                }
                                if (i == 6)
                                {
                                    fullname = txtChildName4.Text.ToUpper();
                                    idnum = ddlChildIdNumber4.GetIdNumber();
                                    birthday = ddlChildDOB4.GetDate();
                                    relationship = "Child";
                                    gender = ddlGenderChild4.GetGender();
                                }
                                if (i == 7)
                                {
                                    fullname = txtChildName5.Text.ToUpper();
                                    idnum = ddlChildIdNumber5.GetIdNumber();
                                    birthday = ddlChildDOB5.GetDate();
                                    relationship = "Child";
                                    gender = ddlGenderChild5.GetGender();
                                }
                                if (i == 8)
                                {
                                    fullname = txtChildName6.Text.ToUpper();
                                    idnum = ddlChildIdNumber6.GetIdNumber();
                                    birthday = ddlChildDOB6.GetDate();
                                    relationship = "Child";
                                    gender = ddlGenderChild6.GetGender();
                                }
                            }
                            else
                            {
                                if (i == 2)
                                {
                                    fullname = txtChildName1.Text.ToUpper();
                                    idnum = ddlChildIdNumber1.GetIdNumber();
                                    birthday = ddlChildDOB1.GetDate();
                                    relationship = "Child";
                                    gender = ddlGenderChild1.GetGender();
                                }
                                if (i == 3)
                                {
                                    fullname = txtChildName2.Text.ToUpper();
                                    idnum = ddlChildIdNumber2.GetIdNumber();
                                    birthday = ddlChildDOB2.GetDate();
                                    relationship = "Child";
                                    gender = ddlGenderChild2.GetGender();
                                }
                                if (i == 4)
                                {
                                    fullname = txtChildName3.Text.ToUpper();
                                    idnum = ddlChildIdNumber3.GetIdNumber();
                                    birthday = ddlChildDOB3.GetDate();
                                    relationship = "Child";
                                    gender = ddlGenderChild3.GetGender();
                                }
                                if (i == 5)
                                {
                                    fullname = txtChildName4.Text.ToUpper();
                                    idnum = ddlChildIdNumber4.GetIdNumber();
                                    birthday = ddlChildDOB4.GetDate();
                                    relationship = "Child";
                                    gender = ddlGenderChild4.GetGender();
                                }
                                if (i == 6)
                                {
                                    fullname = txtChildName5.Text.ToUpper();
                                    idnum = ddlChildIdNumber5.GetIdNumber();
                                    birthday = ddlChildDOB5.GetDate();
                                    relationship = "Child";
                                    gender = ddlGenderChild5.GetGender();
                                }
                                if (i == 7)
                                {
                                    fullname = txtChildName6.Text.ToUpper();
                                    idnum = ddlChildIdNumber6.GetIdNumber();
                                    birthday = ddlChildDOB6.GetDate();
                                    relationship = "Child";
                                    gender = ddlGenderChild6.GetGender();
                                }
                            }

                            //if (i == 2 && Convert.ToInt32(txtNoOfAdult.Text.Trim()) == 2)
                            //{
                            //    fullname = txtSpouseFamily.Text;
                            //    idnum = txtNRICPassSpouseFamily.Text;
                            //    birthday = usrDOBSpouseFamily.GetDate();
                            //    nationality = ddlNationality.GetNationality();
                            //    relationship = "Spouse";
                            //}
                            //else
                            //{
                            //    if (i == 2 && Convert.ToInt32(txtNoOfChild.Text.Trim()) == 1)
                            //    {
                            //        fullname = txtChildName1.Text;
                            //        idnum = ddlChildIdNumber1.GetIdNumber();
                            //        birthday = ddlChildDOB1.GetDate();
                            //        relationship = "Child";
                            //    }
                            //    if (i == 3 && Convert.ToInt32(txtNoOfChild.Text.Trim()) == 1)
                            //    {
                            //        fullname = txtChildName1.Text;
                            //        idnum = ddlChildIdNumber1.GetIdNumber();
                            //        birthday = ddlChildDOB1.GetDate();
                            //        relationship = "Child";
                            //    }
                            //    if (i == 4 && Convert.ToInt32(txtNoOfChild.Text.Trim()) == 2)
                            //    {
                            //        fullname = txtChildName2.Text;
                            //        idnum = ddlChildIdNumber2.GetIdNumber();
                            //        birthday = ddlChildDOB2.GetDate();
                            //        relationship = "Child";
                            //    }
                            //    if (i == 5 && Convert.ToInt32(txtNoOfChild.Text.Trim()) == 3)
                            //    {
                            //        fullname = txtChildName3.Text;
                            //        idnum = ddlChildIdNumber3.GetIdNumber();
                            //        birthday = ddlChildDOB3.GetDate();
                            //        relationship = "Child";
                            //    }
                            //    if (i == 6 && Convert.ToInt32(txtNoOfChild.Text.Trim()) == 4)
                            //    {
                            //        fullname = txtChildName4.Text;
                            //        idnum = ddlChildIdNumber4.GetIdNumber();
                            //        birthday = ddlChildDOB4.GetDate();
                            //        relationship = "Child";
                            //    }
                            //    if (i == 7 && Convert.ToInt32(txtNoOfChild.Text.Trim()) == 5)
                            //    {
                            //        fullname = txtChildName5.Text;
                            //        idnum = ddlChildIdNumber5.GetIdNumber();
                            //        birthday = ddlChildDOB5.GetDate();
                            //        relationship = "Child";
                            //    }
                            //    if (i == 8 && Convert.ToInt32(txtNoOfChild.Text.Trim()) == 6)
                            //    {
                            //        fullname = txtChildName6.Text;
                            //        idnum = ddlChildIdNumber6.GetIdNumber();
                            //        birthday = ddlChildDOB6.GetDate();
                            //        relationship = "Child";
                            //    }
                            //}
                        }

                        _tatravellerstoinsure.TATraId = 0;
                        //_tatravellerstoinsure.TAPersonnelId = _tapersonnel.TAPersonnelId;
                        _tatravellerstoinsure.TAPersonnelId = _tamoreresult;
                        _tatravellerstoinsure.Salutation = salutation;
                        _tatravellerstoinsure.Fullname = fullname;
                        _tatravellerstoinsure.IDType = idtype;
                        _tatravellerstoinsure.IDNumber = idnum;
                        _tatravellerstoinsure.Gender = gender;
                        _tatravellerstoinsure.Birthday = birthday;
                        _tatravellerstoinsure.Nationality = nationality;
                        _tatravellerstoinsure.Relationship = relationship;
                        _tatravellerstoinsure.Info1 = "HSBC";

                        if (Session[General.UserId] != null)
                            _tatravellerstoinsure.RefCEUserId = Convert.ToInt64(Session[General.UserId].ToString());
                        else
                            _tatravellerstoinsure.RefCEUserId = Convert.ToInt64(Session[CE.Global.General.TAPersonnelId].ToString());

                        _tatravellerstoinsure.ViewedDetailId = Convert.ToInt64(Session[General.ViewedDetailsId].ToString());
                        _tatravellerstoinsure.Status = true;

                        TATraId = _tatravellerstoinsuredb.Insert(_tatravellerstoinsure);
                    }

                }
            }

            if (TATraId > 0)
            {
                ProposalNotification();
                UserConfirmation _userconfirm = new UserConfirmation();
                UserConfirmationDB _userconfirmdb = new UserConfirmationDB();
                _userconfirm.ConfirmationType = "TA";
                _userconfirm.CurrentStep = 2;
                _userconfirm.FirstStepId = Convert.ToInt64(Session[General.TAId].ToString());

                if (Session[General.UserId] != null)
                    _userconfirm.RefCEUserId = Convert.ToInt64(Session[General.UserId].ToString());
                else
                    _userconfirm.RefCEUserId = Convert.ToInt64(Session[CE.Global.General.TAPersonnelId].ToString());

                _userconfirm.Status = true;
                _userconfirm.IsConfirm = true;
                _userconfirm.ResultStatus = "Complete";
                _userconfirm.IsComplete = true;
                Int64 _result = _userconfirmdb.Insert(_userconfirm);
                if (_result > 0)
                {
                    string _providerid = Encode(Session[General.ProviderCompanyId].ToString());
                    string convertno = General.GetRefNumber(Convert.ToInt64(Session[General.TAId].ToString()));
                    string _RefNo = "TIH" + convertno;

                    General.ClearAllSession(this.Page, "ALL");
                    Response.Redirect("~/travel-insurance/UserMessage.aspx?pcid=" + _providerid + "&ref=" + _RefNo);
                }
                else
                {
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "ShowMessage", "alert(\"Can't update confirmation status.\"", true);
                }
            }
        }
    }

    public string Encode(string sData)
    {
        byte[] encData_byte = new byte[sData.Length];
        encData_byte = System.Text.Encoding.UTF8.GetBytes(sData);
        string encodedData = Convert.ToBase64String(encData_byte);
        return encodedData;
    }

    private Int64 LogUserViewedHistory()
    {
        UserViewHistoryDB _userviewdb = new UserViewHistoryDB();
        return _userviewdb.LogViewedHistory("TA", Request, "Travel Insurance applicant's details.");
    }

    private void CheckValidation()
    {
        int NoOfTravellers = Convert.ToInt32(lblNoOfTravellers.Text.ToString());


        usrDOB.IsEnableValidation(false);
        usrDOBinsured.IsEnableValidation(false);
        usrDOBSpouse.IsEnableValidation(false);
        usrDOBInsuredFamily.IsEnableValidation(false);
        usrDOBSpouseFamily.IsEnableValidation(false);
        csvNRIC.Enabled = false;
        cvNRICfamily.Enabled = false;

        if (divIndividual.Visible == true)
        {
            usrDOB.IsEnableValidation(true);
        }
        else if (divWithspouse.Visible == true)
        {
            usrDOBinsured.IsEnableValidation(true);
            usrDOBSpouse.IsEnableValidation(true);
            csvNRIC.Enabled = true;
        }
        else if (divFamily.Visible == true)
        {
            usrDOBInsuredFamily.IsEnableValidation(true);
            usrDOBSpouseFamily.IsEnableValidation(true);
            cvNRICfamily.Enabled = true;
        }


        txtPostCode.Text = General.ClearScriptTag(txtPostCode.Text);
        txtUnit1.Text = General.ClearScriptTag(txtUnit1.Text);
        txtUnit2.Text = General.ClearScriptTag(txtUnit2.Text);
        txtAddress.Text = General.ClearScriptTag(txtAddress.Text);

        //txtBank.Text = General.ClearScriptTag(txtBank.Text);
        //txtChequeNo.Text = General.ClearScriptTag(txtChequeNo.Text);
        txtNameoftheCard.Text = General.ClearScriptTag(txtNameoftheCard.Text);
        txtIssuingBank.Text = General.ClearScriptTag(txtIssuingBank.Text);
        txtCardNo1.Text = General.ClearScriptTag(txtCardNo1.Text);
        txtCardNo2.Text = General.ClearScriptTag(txtCardNo2.Text);
        txtCardNo3.Text = General.ClearScriptTag(txtCardNo3.Text);
        txtCardNo4.Text = General.ClearScriptTag(txtCardNo4.Text);
        //txtCardExpiryMonth.Text = General.ClearScriptTag(txtCardExpiryMonth.Text);
        //txtCardExpiryYear.Text = General.ClearScriptTag(txtCardExpiryYear.Text);

        //#region Payment Mode
        //if (rdoCashorNets.Checked)
        //{
        //    rfvBank.Enabled = false;
        //    rfvChequeNo.Enabled = false;
        //    revChequeNo.Enabled = false;
        //    rfvNameoftheCard.Enabled = false;
        //    rfvIssuingBank.Enabled = false;
        //    rfvCardNo1.Enabled = false;
        //    revCardNo1.Enabled = false;
        //    rfvCardNo2.Enabled = false;
        //    revCardNo2.Enabled = false;
        //    rfvCardNo3.Enabled = false;
        //    revCardNo3.Enabled = false;
        //    rfvCardNo4.Enabled = false;
        //    revCardNo4.Enabled = false;
        //    rfvCardExpiryMonth.Enabled = false;
        //    revCardExpiryMonth.Enabled = false;
        //    rfvCardExpiryYear.Enabled = false;
        //    revCardExpiryYear.Enabled = false;
        //    rfvCardType.Enabled = false;
        //}
        //else if (rdoCheque.Checked)
        //{
        //    rfvBank.Enabled = true;
        //    rfvChequeNo.Enabled = true;
        //    revChequeNo.Enabled = true;
        //    rfvNameoftheCard.Enabled = false;
        //    rfvIssuingBank.Enabled = false;
        //    rfvCardNo1.Enabled = false;
        //    revCardNo1.Enabled = false;
        //    rfvCardNo2.Enabled = false;
        //    revCardNo2.Enabled = false;
        //    rfvCardNo3.Enabled = false;
        //    revCardNo3.Enabled = false;
        //    rfvCardNo4.Enabled = false;
        //    revCardNo4.Enabled = false;
        //    rfvCardExpiryMonth.Enabled = false;
        //    revCardExpiryMonth.Enabled = false;
        //    rfvCardExpiryYear.Enabled = false;
        //    revCardExpiryYear.Enabled = false;
        //    rfvCardType.Enabled = false;
        //}
        //else if (rdoCreditCard.Checked)
        //{
        //    rfvBank.Enabled = false;
        //    rfvChequeNo.Enabled = false;
        //    revChequeNo.Enabled = false;
        //    rfvNameoftheCard.Enabled = true;
        //    rfvIssuingBank.Enabled = true;
        //    rfvCardNo1.Enabled = true;
        //    revCardNo1.Enabled = true;
        //    rfvCardNo2.Enabled = true;
        //    revCardNo2.Enabled = true;
        //    rfvCardNo3.Enabled = true;
        //    revCardNo3.Enabled = true;
        //    rfvCardNo4.Enabled = true;
        //    revCardNo4.Enabled = true;
        //    rfvCardExpiryMonth.Enabled = true;
        //    revCardExpiryMonth.Enabled = true;
        //    rfvCardExpiryYear.Enabled = true;
        //    revCardExpiryYear.Enabled = true;
        //    rfvCardType.Enabled = true;
        //}
        //#endregion
    }

    private void ChangeValidationEffectServerSide(string strValidationGroup)
    {
        #region Particulars of Proposer

        ddlSalutation.ChangeValidationEffectServerSide(strValidationGroup);

        if (rfvFirstname.Enabled && rfvFirstname.ValidationGroup == strValidationGroup)
        {
            rfvFirstname.Validate();
            if (rfvFirstname.IsValid == false)
            {
                txtFirstname.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtFirstname.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtFirstname.ControlStyle.CssClass = "";
        }


        if (rfvSurname.Enabled && rfvSurname.ValidationGroup == strValidationGroup)
        {
            rfvSurname.Validate();
            if (rfvSurname.IsValid == false)
            {
                txtSurname.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtSurname.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtSurname.ControlStyle.CssClass = "";
        }

        if (revEmailAddress.Enabled && revEmailAddress.ValidationGroup == strValidationGroup)
        {
            if (rfvEmailAddress.IsValid)
            {
                revEmailAddress.Validate();
                if (revEmailAddress.IsValid == false)
                {
                    txtEmailAddress.ControlStyle.CssClass = "validationError";
                }
                else
                {
                    txtEmailAddress.ControlStyle.CssClass = "";
                }
            }
        }
        else
        {
            txtEmailAddress.ControlStyle.CssClass = "";
            
        }
        ddlGender.ChangeValidationEffectServerSide(strValidationGroup);

        //usrGEnder.ChangeValidationEffectServerSide(strValidationGroup);
        //usrIdType.ChangeValidationEffectServerSide(strValidationGroup);
        //usrIdNumber.ChangeValidationEffectServerSide(strValidationGroup);
        ddlNationality.ChangeValidationEffectServerSide(strValidationGroup);
        txtMobileNo.ChangeValidationEffectServerSide(strValidationGroup);
        txtOfficeNo.ChangeValidationEffectServerSide(strValidationGroup);
        txtResidentialPhoneNo.ChangeValidationEffectServerSide(strValidationGroup);

        usrDOB.ChangeValidationEffectServerSide(strValidationGroup);
        usrDOBinsured.ChangeValidationEffectServerSide(strValidationGroup);
        usrDOBInsuredFamily.ChangeValidationEffectServerSide(strValidationGroup);
        usrDOBSpouse.ChangeValidationEffectServerSide(strValidationGroup);
        usrDOBSpouseFamily.ChangeValidationEffectServerSide(strValidationGroup);

        #endregion

        #region Payment Mode

        ////Payment Mode
        //if (rfvPaymentMode.Enabled && rfvPaymentMode.ValidationGroup == strValidationGroup)
        //{
        //    rfvPaymentMode.Validate();
        //    if (rfvPaymentMode.IsValid == false)
        //    {
        //        lblCashorNets.ControlStyle.CssClass = "validationError";
        //        lblCheque.ControlStyle.CssClass = "validationError";
        //        lblCreditCard.ControlStyle.CssClass = "validationError";
        //    }
        //    else
        //    {
        //        lblCashorNets.ControlStyle.CssClass = "";
        //        lblCheque.ControlStyle.CssClass = "";
        //        lblCreditCard.ControlStyle.CssClass = "";
        //    }
        //}
        //else
        //{
        //    lblCashorNets.ControlStyle.CssClass = "";
        //    lblCheque.ControlStyle.CssClass = "";
        //    lblCreditCard.ControlStyle.CssClass = "";
        //}

        ////Bank Name
        //if (rfvBank.Enabled && rfvBank.ValidationGroup == strValidationGroup)
        //{
        //    rfvBank.Validate();
        //    if (rfvBank.IsValid == false)
        //    {
        //        txtBank.ControlStyle.CssClass = "validationError";
        //    }
        //    else
        //    {
        //        txtBank.ControlStyle.CssClass = "";
        //    }
        //}
        //else
        //{
        //    txtBank.ControlStyle.CssClass = "";
        //}
        ////Cheque No
        //if (rfvChequeNo.Enabled && rfvChequeNo.ValidationGroup == strValidationGroup)
        //{
        //    rfvChequeNo.Validate();
        //    if (rfvChequeNo.IsValid == false)
        //    {
        //        txtChequeNo.ControlStyle.CssClass = "validationError";
        //    }
        //    else
        //    {
        //        txtChequeNo.ControlStyle.CssClass = "";
        //    }
        //}
        //else
        //{
        //    txtChequeNo.ControlStyle.CssClass = "";
        //}

        //if (revChequeNo.Enabled && revChequeNo.ValidationGroup == strValidationGroup)
        //{
        //    if (rfvChequeNo.IsValid)
        //    {
        //        revChequeNo.Validate();
        //        if (revChequeNo.IsValid == false)
        //        {
        //            txtChequeNo.ControlStyle.CssClass = "validationError";
        //        }
        //        else
        //        {
        //            txtChequeNo.ControlStyle.CssClass = "";
        //        }
        //    }
        //}
        //else
        //{
        //    txtChequeNo.ControlStyle.CssClass = "";
        //}
        //Name of the Card
        if (rfvNameoftheCard.Enabled && rfvNameoftheCard.ValidationGroup == strValidationGroup)
        {
            rfvNameoftheCard.Validate();
            if (rfvNameoftheCard.IsValid == false)
            {
                txtNameoftheCard.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtNameoftheCard.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtNameoftheCard.ControlStyle.CssClass = "";
        }
        //Issuing Bank
        if (rfvIssuingBank.Enabled && rfvIssuingBank.ValidationGroup == strValidationGroup)
        {
            rfvIssuingBank.Validate();
            if (rfvIssuingBank.IsValid == false)
            {
                txtIssuingBank.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtIssuingBank.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtIssuingBank.ControlStyle.CssClass = "";
        }
        //Card 1
        if (rfvCardNo1.Enabled && rfvCardNo1.ValidationGroup == strValidationGroup)
        {
            rfvCardNo1.Validate();
            if (rfvCardNo1.IsValid == false)
            {
                txtCardNo1.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtCardNo1.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtCardNo1.ControlStyle.CssClass = "";
        }

        if (revCardNo1.Enabled && revCardNo1.ValidationGroup == strValidationGroup)
        {
            if (rfvCardNo1.IsValid)
            {
                revCardNo1.Validate();
                if (revCardNo1.IsValid == false)
                {
                    txtCardNo1.ControlStyle.CssClass = "validationError";
                }
                else
                {
                    txtCardNo1.ControlStyle.CssClass = "";
                }
            }
        }
        else
        {
            txtCardNo1.ControlStyle.CssClass = "";
        }
        //Card 2
        if (rfvCardNo2.Enabled && rfvCardNo2.ValidationGroup == strValidationGroup)
        {
            rfvCardNo2.Validate();
            if (rfvCardNo2.IsValid == false)
            {
                txtCardNo2.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtCardNo2.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtCardNo2.ControlStyle.CssClass = "";
        }

        if (revCardNo2.Enabled && revCardNo2.ValidationGroup == strValidationGroup)
        {
            if (rfvCardNo2.IsValid)
            {
                revCardNo2.Validate();
                if (revCardNo2.IsValid == false)
                {
                    txtCardNo2.ControlStyle.CssClass = "validationError";
                }
                else
                {
                    txtCardNo2.ControlStyle.CssClass = "";
                }
            }
        }
        else
        {
            txtCardNo2.ControlStyle.CssClass = "";
        }
        //Card 3
        if (rfvCardNo3.Enabled && rfvCardNo3.ValidationGroup == strValidationGroup)
        {
            rfvCardNo3.Validate();
            if (rfvCardNo3.IsValid == false)
            {
                txtCardNo3.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtCardNo3.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtCardNo3.ControlStyle.CssClass = "";
        }

        if (revCardNo3.Enabled && revCardNo3.ValidationGroup == strValidationGroup)
        {
            if (rfvCardNo3.IsValid)
            {
                revCardNo3.Validate();
                if (revCardNo3.IsValid == false)
                {
                    txtCardNo3.ControlStyle.CssClass = "validationError";
                }
                else
                {
                    txtCardNo3.ControlStyle.CssClass = "";
                }
            }
        }
        else
        {
            txtCardNo3.ControlStyle.CssClass = "";
        }
        //Card 4
        if (rfvCardNo4.Enabled && rfvCardNo4.ValidationGroup == strValidationGroup)
        {
            rfvCardNo4.Validate();
            if (rfvCardNo4.IsValid == false)
            {
                txtCardNo4.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtCardNo4.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtCardNo4.ControlStyle.CssClass = "";
        }

        if (revCardNo4.Enabled && revCardNo4.ValidationGroup == strValidationGroup)
        {
            if (rfvCardNo4.IsValid)
            {
                revCardNo4.Validate();
                if (revCardNo4.IsValid == false)
                {
                    txtCardNo4.ControlStyle.CssClass = "validationError";
                }
                else
                {
                    txtCardNo4.ControlStyle.CssClass = "";
                }
            }
        }
        else
        {
            txtCardNo4.ControlStyle.CssClass = "";
        }
        //Card Expiry Month
        if (rfvCardExpiryMonth.Enabled && rfvCardExpiryMonth.ValidationGroup == strValidationGroup)
        {
            rfvCardExpiryMonth.Validate();
            if (rfvCardExpiryMonth.IsValid == false)
            {
                ddlCardExpiryMonth.ControlStyle.CssClass = "validationError";
            }
            else
            {
                ddlCardExpiryMonth.ControlStyle.CssClass = "";
            }
        }
        else
        {
            ddlCardExpiryMonth.ControlStyle.CssClass = "";
        }

        //if (revCardExpiryMonth.Enabled && revCardExpiryMonth.ValidationGroup == strValidationGroup)
        //{
        //    if (rfvCardExpiryMonth.IsValid)
        //    {
        //        revCardExpiryMonth.Validate();
        //        if (revCardExpiryMonth.IsValid == false)
        //        {
        //            txtCardExpiryMonth.ControlStyle.CssClass = "validationError";
        //        }
        //        else
        //        {
        //            txtCardExpiryMonth.ControlStyle.CssClass = "";
        //        }
        //    }
        //}
        //else
        //{
        //    txtCardExpiryMonth.ControlStyle.CssClass = "";
        //}
        //Card Expiry Year
        if (rfvCardExpiryYear.Enabled && rfvCardExpiryYear.ValidationGroup == strValidationGroup)
        {
            rfvCardExpiryYear.Validate();
            if (rfvCardExpiryYear.IsValid == false)
            {
                ddlCardExpiryYear.ControlStyle.CssClass = "validationError";
            }
            else
            {
                ddlCardExpiryYear.ControlStyle.CssClass = "";
            }
        }
        else
        {
            ddlCardExpiryYear.ControlStyle.CssClass = "";
        }

        //if (revCardExpiryYear.Enabled && revCardExpiryYear.ValidationGroup == strValidationGroup)
        //{
        //    if (rfvCardExpiryYear.IsValid)
        //    {
        //        revCardExpiryYear.Validate();
        //        if (revCardExpiryYear.IsValid == false)
        //        {
        //            txtCardExpiryYear.ControlStyle.CssClass = "validationError";
        //        }
        //        else
        //        {
        //            txtCardExpiryYear.ControlStyle.CssClass = "";
        //        }
        //    }
        //}
        //else
        //{
        //    txtCardExpiryYear.ControlStyle.CssClass = "";
        //}
        //CardType
        if (rfvCardType.Enabled && rfvCardType.ValidationGroup == strValidationGroup)
        {
            rfvCardType.Validate();
            if (rfvCardType.IsValid == false)
            {
                lblVisa.ControlStyle.CssClass = "validationError";
                lblMasterCard.ControlStyle.CssClass = "validationError";
            }
            else
            {
                lblVisa.ControlStyle.CssClass = "";
                lblMasterCard.ControlStyle.CssClass = "";
            }
        }
        else
        {
            lblVisa.ControlStyle.CssClass = "";
            lblMasterCard.ControlStyle.CssClass = "";
        }

        #endregion

        #region Travellers Info


        if (rfvNameOfInsured.Enabled && rfvNameOfInsured.ValidationGroup == strValidationGroup)
        {
            rfvNameOfInsured.Validate();
            if (rfvNameOfInsured.IsValid == false)
            {
                txtNameOfInsured.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtNameOfInsured.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtNameOfInsured.ControlStyle.CssClass = "";
        }

        if (rfvNRICPass.Enabled && rfvNRICPass.ValidationGroup == strValidationGroup)
        {
            rfvNRICPass.Validate();
            if (rfvNRICPass.IsValid == false)
            {
                txtNRICPass.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtNRICPass.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtNRICPass.ControlStyle.CssClass = "";
        }

        if (rfvInsured.Enabled && rfvInsured.ValidationGroup == strValidationGroup)
        {
            rfvInsured.Validate();
            if (rfvInsured.IsValid == false)
            {
                txtInsured.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtInsured.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtInsured.ControlStyle.CssClass = "";
        }

        if (rfvNRICPassInsured.Enabled && rfvNRICPassInsured.ValidationGroup == strValidationGroup)
        {
            rfvNRICPassInsured.Validate();
            if (rfvInsured.IsValid == false)
            {
                txtNRICPassInsured.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtNRICPassInsured.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtNRICPassInsured.ControlStyle.CssClass = "";
        }

        if (rfvSpouse.Enabled && rfvSpouse.ValidationGroup == strValidationGroup)
        {
            rfvSpouse.Validate();
            if (rfvSpouse.IsValid == false)
            {
                txtSpouse.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtSpouse.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtSpouse.ControlStyle.CssClass = "";
        }

        if (rfvNRICPassSpouse.Enabled && rfvNRICPassSpouse.ValidationGroup == strValidationGroup)
        {
            rfvNRICPassSpouse.Validate();
            if (rfvSpouse.IsValid == false)
            {
                txtNRICPassSpouse.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtNRICPassSpouse.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtNRICPassSpouse.ControlStyle.CssClass = "";
        }

        if (rfvInsuredFamily.Enabled && rfvInsuredFamily.ValidationGroup == strValidationGroup)
        {
            rfvInsuredFamily.Validate();
            if (rfvInsuredFamily.IsValid == false)
            {
                txtInsuredFamily.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtInsuredFamily.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtInsuredFamily.ControlStyle.CssClass = "";
        }

        if (rfvNRICPassInsuredFamily.Enabled && rfvNRICPassInsuredFamily.ValidationGroup == strValidationGroup)
        {
            rfvNRICPassInsuredFamily.Validate();
            if (rfvNRICPassInsuredFamily.IsValid == false)
            {
                txtNRICPassInsuredFamily.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtNRICPassInsuredFamily.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtNRICPassInsuredFamily.ControlStyle.CssClass = "";
        }

        if (rfvSpouseFamily.Enabled && rfvSpouseFamily.ValidationGroup == strValidationGroup)
        {
            rfvSpouseFamily.Validate();
            if (rfvSpouseFamily.IsValid == false)
            {
                txtSpouseFamily.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtSpouseFamily.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtSpouseFamily.ControlStyle.CssClass = "";
        }

        if (rfvNRICPassSpouseFamily.Enabled && rfvNRICPassSpouseFamily.ValidationGroup == strValidationGroup)
        {
            rfvNRICPassSpouseFamily.Validate();
            if (rfvNRICPassSpouseFamily.IsValid == false)
            {
                txtNRICPassSpouseFamily.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtNRICPassSpouseFamily.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtNRICPassSpouseFamily.ControlStyle.CssClass = "";
        }

        if (rfvNoOfChild.Enabled && rfvNoOfChild.ValidationGroup == strValidationGroup)
        {
            rfvNoOfChild.Validate();
            if (rfvNoOfChild.IsValid == false)
            {
                txtNoOfChild.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtNoOfChild.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtNoOfChild.ControlStyle.CssClass = "";
        }
        
        ddlGenderIndividual.ChangeValidationEffectServerSide(strValidationGroup);
        ddlGenderSpouse.ChangeValidationEffectServerSide(strValidationGroup);
        ddlGenderWithSpouse.ChangeValidationEffectServerSide(strValidationGroup);
        ddlGenderFamily.ChangeValidationEffectServerSide(strValidationGroup);
        ddlGenderSpouseFamily.ChangeValidationEffectServerSide(strValidationGroup);

        ddlGenderChild1.ChangeValidationEffectServerSide(strValidationGroup);
        ddlGenderChild2.ChangeValidationEffectServerSide(strValidationGroup);
        ddlGenderChild3.ChangeValidationEffectServerSide(strValidationGroup);
        ddlGenderChild4.ChangeValidationEffectServerSide(strValidationGroup);
        ddlGenderChild5.ChangeValidationEffectServerSide(strValidationGroup);
        ddlGenderChild6.ChangeValidationEffectServerSide(strValidationGroup);

        #endregion

    }

    protected void csvCreditCardValid_ServerValidate(object source, ServerValidateEventArgs args)
    {
        bool _status = true;
        string _first = "";

        if (txtCardNo1.Text.Length > 0)
        {
            _first = txtCardNo1.Text.Trim().Substring(0, 1);
        }

        if (rdoVisa.Checked)
        {
            if (_first != "4")
            {
                _status = false;
            }
        }
        else if (rdoMasterCard.Checked)
        {
            if (_first != "5")
            {
                _status = false;
            }
        }
        if (_status == true)
        {
            txtCreditCardValid.Text = "";
            txtCreditCardValid.Text = txtCardNo1.Text.Trim() + "" + txtCardNo2.Text.Trim() + "" + txtCardNo3.Text.Trim() + "" + txtCardNo4.Text.Trim();
            string _cardNumer = txtCreditCardValid.Text;
            MySecurity _mysecurity = new MySecurity();
            if (_mysecurity.IsCreditCardValid(_cardNumer))
            {
                args.IsValid = true;
            }
            else
            {
                args.IsValid = false;
            }
        }
        else
        {
            args.IsValid = false;
        }
    }

    protected void csvCCExpiredValid_ServerValidate(object source, ServerValidateEventArgs args)
    {
        txtCCExpiredValid.Text = "";
        txtCCExpiredValid.Text = "valid";
        Int32 _Year = Convert.ToInt32(ddlCardExpiryYear.Text);
        Int32 _Month = Convert.ToInt32(ddlCardExpiryMonth.Text);

        MySecurity _mysecurity = new MySecurity();
        if (_mysecurity.IsCreditCardExpiredDateValid(_Year, _Month))
        {
            args.IsValid = true;
        }
        else
        {
            args.IsValid = false;
        }
    }

    private void ClearSession()
    {
        Session[General.TAPersonnelId] = null;
        //Session[General.TAId] = null;
        //Session[General.TAResultId] = null;
    }

    private void ShowUserDetails()
    {
        //hplEditProfile.Visible = true;
        CE.User.Profile _profile = new CE.User.Profile();
        CE.User.ProfileDB _profiledb = new ProfileDB();
        CE.User.Contact _contact = new Contact();
        CE.User.ContactDB _contactdb = new ContactDB();

        Int64 UserId = Convert.ToInt64(Session[General.UserId].ToString());
        _profile = _profiledb.GetProfile(UserId);
        if (_profile != null)
        {
            
            txtFirstname.Text = _profile.FirstName;
            txtSurname.Text = _profile.SurName;

            if (_profile.Nationality != "")
            {
                ddlNationality.Nationality = _profile.Nationality.ToString();
            }

            _contact = _contactdb.GetContact(UserId);
            if (_contact != null)
            {
                txtMobileNo.PhoneNo = _contact.Mobile;
                txtOfficeNo.PhoneNo = _contact.OfficePhone;
                txtEmailAddress.Text = _contact.Email.ToString();

            }

            _profile = null;
            _profiledb = null;
            _contact = null;
            _contactdb = null;
        }


    }

    private void ChangeDateSettings()
    {
        usrDOB.StartYear = CE.Global.General.GetUTCDateTime().Year - 100;
        usrDOB.EndYear = CE.Global.General.GetUTCDateTime().Year - 18;

        usrDOBinsured.StartYear = CE.Global.General.GetUTCDateTime().Year - 100;
        usrDOBinsured.EndYear = CE.Global.General.GetUTCDateTime().Year - 18;

        usrDOBInsuredFamily.StartYear = CE.Global.General.GetUTCDateTime().Year - 100;
        usrDOBInsuredFamily.EndYear = CE.Global.General.GetUTCDateTime().Year - 18;

        usrDOBSpouse.StartYear = CE.Global.General.GetUTCDateTime().Year - 100;
        usrDOBSpouse.EndYear = CE.Global.General.GetUTCDateTime().Year - 18;

        usrDOBSpouseFamily.StartYear = CE.Global.General.GetUTCDateTime().Year - 100;
        usrDOBSpouseFamily.EndYear = CE.Global.General.GetUTCDateTime().Year - 18;

        ddlChildDOB1.StartYear = CE.Global.General.GetUTCDateTime().Year - 25;
        ddlChildDOB1.EndYear = CE.Global.General.GetUTCDateTime().Year;

        ddlChildDOB2.StartYear = CE.Global.General.GetUTCDateTime().Year - 25;
        ddlChildDOB2.EndYear = CE.Global.General.GetUTCDateTime().Year;

        ddlChildDOB3.StartYear = CE.Global.General.GetUTCDateTime().Year - 25;
        ddlChildDOB3.EndYear = CE.Global.General.GetUTCDateTime().Year;

        ddlChildDOB4.StartYear = CE.Global.General.GetUTCDateTime().Year - 25;
        ddlChildDOB4.EndYear = CE.Global.General.GetUTCDateTime().Year;

        ddlChildDOB5.StartYear = CE.Global.General.GetUTCDateTime().Year - 25;
        ddlChildDOB5.EndYear = CE.Global.General.GetUTCDateTime().Year;

        ddlChildDOB6.StartYear = CE.Global.General.GetUTCDateTime().Year - 25;
        ddlChildDOB6.EndYear = CE.Global.General.GetUTCDateTime().Year;

    }

    protected void ibtnBack_Click(object sender, ImageClickEventArgs e)
    {
        //Response.Redirect("travel_quote.aspx");
        Response.Redirect("~/travel-insurance/TAresultsquotesOne.aspx");
    }

    protected void Check2NRICValid(object sender, ServerValidateEventArgs args)
    {
        string _appID = txtNRICPassInsured.Text;
        string _spouseID = txtNRICPassSpouse.Text;

        if (_appID == _spouseID)
        {
            args.IsValid = false;
        }
        else
        {
            args.IsValid = true;
        }

    }

    protected void Check2NRICValidFamily(object sender, ServerValidateEventArgs args)
    {
        string _appID = txtNRICPassInsuredFamily.Text;
        string _spouseID = txtNRICPassSpouseFamily.Text;

        if (_appID == _spouseID)
        {
            args.IsValid = false;
        }
        else
        {
            args.IsValid = true;
        }

    }

    private void ProposalNotification()
    {
        string _strSql, _providerName, _providerEmail,_providerCCEmail, _providerBCCEmail, _Date, _Time, _InsuranceName, _RefNo;
        MyDatabase _db = new MyDatabase();
        DataTable _dtProvider = new DataTable();
        DataTable _dtInsurance = new DataTable();
        _Date = "";
        _Time = "";
        _RefNo = "";
        _strSql = "";
        _providerName = "";
        _providerEmail = "";
        _providerCCEmail = "";
        _providerBCCEmail = "";

        _InsuranceName = "Travel Insurance";
        _strSql = "SELECT [CompanyName], [Email1] FROM tblProviderCompany WHERE ProviderCompanyId = " + Session[CE.Global.General.ProviderCompanyId].ToString();
        _dtProvider = _db.GetDataTable(_strSql);
        
        if (_dtProvider.Rows.Count > 0)
        {
            _providerName = _dtProvider.Rows[0]["CompanyName"].ToString() + " Insurance";
        }

        _providerEmail = CE.Configuration.MyConfigurationManager.GetAppSettingValue("HSBCTI_TO");
        _providerCCEmail = CE.Configuration.MyConfigurationManager.GetAppSettingValue("HSBCTI_CC");
        _providerBCCEmail = CE.Configuration.MyConfigurationManager.GetAppSettingValue("HSBCTI_BCC");

        _strSql = "";
        _strSql = "SELECT CONVERT(VARCHAR,ModifiedDate,103) AS [Date], CONVERT(VARCHAR,ModifiedDate,108) AS [Time] ";
        _strSql += " FROM  tblTAMoreDetail_HSBC WHERE Info2 = " + Session[General.TAId].ToString() + " ORDER BY ModifiedDate DESC";
        _dtInsurance = _db.GetDataTable(_strSql);
        if (_dtInsurance.Rows.Count > 0)
        {
            _Date = _dtInsurance.Rows[0]["Date"].ToString();
            _Time = _dtInsurance.Rows[0]["Time"].ToString();
        }

        string convertno = General.GetRefNumber(Convert.ToInt64(Session[General.TAId].ToString()));
        _RefNo = "TIH" + convertno;

        if ((_dtProvider.Rows.Count > 0) && (_dtInsurance.Rows.Count > 0))
        {
            MyMailManager.SendProposalCompleteNotification(_providerName, _providerEmail,_providerCCEmail, _providerBCCEmail, _InsuranceName, _Date, _Time, _RefNo);
        }

    }

    protected void ibtPostCode_Click(object sender, ImageClickEventArgs e)
    {
        GetPostCode();
    }

    protected void txtPostCode_TextChanged(object sender, EventArgs e)
    {
        GetPostCode();
    }

    protected void ddlAddressList_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (ddlAddressList.Items.Count > 0 && ddlAddressList.SelectedIndex >= 0)
        {
            txtAddress.Text = ddlAddressList.Text;
        }
    }

    private void GetPostCode()
    {
        rfvPostCode.Validate();
        revPostCode.Validate();
        if (rfvPostCode.IsValid && revPostCode.IsValid)
        {
            txtPostCode.ControlStyle.CssClass = "";
            txtAddress.ControlStyle.CssClass = "";
            MyLocation _myLoc = new MyLocation();
            //string _strAddress = _myLoc.GetAddressByPostCode(txtPostCode.Text);
            //if (_strAddress != null && _strAddress != string.Empty)
            //{
            //    if (_strAddress.ToLower().Contains("invalid api"))
            //    {
            //        txtAddress.Text = "Address can't be retrieved. Please type your address detail here.";
            //    }
            //    else
            //    {
            //        txtAddress.Text = _strAddress;
            //    }
            //}
            //else
            //{
            //    txtAddress.Text = "Address is not found.";
            //}

            System.Data.DataSet _ds = _myLoc.GetAddressByPostCodeDataSet(txtPostCode.Text);
            ddlAddressList.Items.Clear();
            string _lstValue;
            string _lstText;
            int _rowCount = 0;

            if (_ds != null)
            {
                if (_ds.Tables.Count > 0)
                {
                    foreach (System.Data.DataTable _dt in _ds.Tables)
                    {
                        if (_dt.Rows.Count > 0)
                        {
                            foreach (System.Data.DataRow _dr in _dt.Rows)
                            {
                                //lblAddress2.Text += _dr["t"].ToString() + "<br />";
                                //lblAddress2.Text += _dr["a"].ToString() + "<br /><br />";

                                _lstValue = _dr["t"].ToString() + ", " + _dr["a"].ToString();
                                _lstText = _dr["t"].ToString();
                                ddlAddressList.Items.Add(new ListItem(_lstText, _lstValue));
                                if (_rowCount == 0)
                                {
                                    txtAddress.Text = _lstValue;
                                    //ibtPostCode.Enabled = false;
                                    txtAddress.ReadOnly = true;
                                }

                                _rowCount++;
                            }
                        }
                        else
                        {
                            txtAddress.Text = "No address found.";
                            txtAddress.ReadOnly = false;
                            txtAddress.ControlStyle.CssClass = "validationError";
                        }
                    }
                }
                else
                {
                    txtAddress.Text = "No address found.";
                    txtAddress.ReadOnly = false;
                    txtAddress.ControlStyle.CssClass = "validationError";
                }
            }
            else
            {
                txtAddress.Text = "Please type your address here.";
                txtAddress.ReadOnly = false;
                txtAddress.ControlStyle.CssClass = "validationError";
            }

            if (_rowCount > 1)
            {
                divAddressList.Visible = true;
            }
            else
            {
                divAddressList.Visible = false;

            }
        }
        else
        {
            txtPostCode.ControlStyle.CssClass = "validationError";
            ddlAddressList.Items.Clear();
            divAddressList.Visible = false;
            txtAddress.Text = "Invalid postcode.";
            txtAddress.ControlStyle.CssClass = "validationError";
        }
    }
    
    private void ValidateAdult1(bool OnOff)
    {
        rfvAdultName1.Enabled = OnOff;
        revAdultName1.Enabled = OnOff;
        ddlAdultIdNumber1.IsEnableValidation(OnOff);
    }

    private void ValidateAdult2(bool OnOff)
    {
        rfvAdultName2.Enabled = OnOff;
        revAdultName2.Enabled = OnOff;
        ddlAdultIdNumber2.IsEnableValidation(OnOff);
    }

    private void ValidateChild1(bool OnOff)
    {
        rfvChildName1.Enabled = OnOff;
        revChildName1.Enabled = OnOff;
        ddlChildIdNumber1.IsEnableValidation(OnOff);
        ddlGenderChild1.IsEnableValidation(OnOff);
    }

    private void ValidateChild2(bool OnOff)
    {
        rfvChildName2.Enabled = OnOff;
        revChildName2.Enabled = OnOff;
        ddlChildIdNumber2.IsEnableValidation(OnOff);
        ddlGenderChild2.IsEnableValidation(OnOff);
    }

    private void ValidateChild3(bool OnOff)
    {
        rfvChildName3.Enabled = OnOff;
        revChildName3.Enabled = OnOff;
        ddlChildIdNumber3.IsEnableValidation(OnOff);
        ddlGenderChild3.IsEnableValidation(OnOff);
    }

    private void ValidateChild4(bool OnOff)
    {
        rfvChildName4.Enabled = OnOff;
        revChildName4.Enabled = OnOff;
        ddlChildIdNumber4.IsEnableValidation(OnOff);
        ddlGenderChild4.IsEnableValidation(OnOff);
    }

    private void ValidateChild5(bool OnOff)
    {
        rfvChildName5.Enabled = OnOff;
        revChildName5.Enabled = OnOff;
        ddlChildIdNumber5.IsEnableValidation(OnOff);
        ddlGenderChild5.IsEnableValidation(OnOff);
    }

    private void ValidateChild6(bool OnOff)
    {
        rfvChildName6.Enabled = OnOff;
        revChildName6.Enabled = OnOff;
        ddlChildIdNumber6.IsEnableValidation(OnOff);
        ddlGenderChild6.IsEnableValidation(OnOff);
    }

    protected void CheckSalGenderValid(object sender, ServerValidateEventArgs args)
    {
        string _sal = ddlSalutation.GetSalutation();
        string _gender = ddlGender.GetGender();
        if (_gender == "M")
        {
            if (_sal == "Ms" || _sal == "Miss" || _sal == "Mdm" || _sal == "Mrs")
            {
                args.IsValid = false;
            }
        }
        else if (_gender == "F")
        {
            if (_sal == "Mr")
            {
                args.IsValid = false;
            }
        }
        else
        {
            args.IsValid = true;
        }
    }


}
